package com.uchedao.mybaselibrary.http;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * 网络请求管理器－－单例
 * Created by Administrator on 2015/6/2.
 */
public class VolleyUtil {
    /**
     * 单例
     */
    private static VolleyUtil mInstance;
    /**
     * 网络请求管理
     */
    private RequestQueue mRequestQueue;

    private VolleyUtil(Context context) {
        mRequestQueue = getRequestQueue(context);
    }

    /**
     * 获取单例
     */
    public static synchronized VolleyUtil getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new VolleyUtil(context);
        }
        return mInstance;
    }

    public RequestQueue getRequestQueue(Context context) {
        if (mRequestQueue == null) {
            // getApplicationContext() is key, it keeps you from leaking the
            // Activity or BroadcastReceiver if someone passes one in.
            mRequestQueue = Volley.newRequestQueue(context);
        }
        return mRequestQueue;
    }

}
